#include "Stack.h"

Stack::Stack() //初始化，构造
{
    base = new ElemType[MAXSIZE];
    top = base;
    size = MAXSIZE;
}
void Stack::Push() //入栈
{
    if (top - base == size) //!
    {
        cout << "该栈已满！" << endl;
        return;
    } else {
        ElemType e;
        cout << "请输入想入栈的元素：";
        cin >> e;
        *top = e; //!
        top++;    //!
        cout << "入栈成功！" << endl;
        return;
    }
}
void Stack::Pop() //出栈
{
    if (top == base) //!
    {
        cout << "栈为空！" << endl;
        return;
    } else {
        top--;                                  //!
        cout << "出栈元素为：" << *top << endl; //! *top
        return;
    }
}
bool Stack::IsEmpty() //栈是否为空
{
    if (top == base)
        return true;
    else
        return false;
}
int Stack::Length() //得到栈的长度
{
    return top - base;
}
void Stack::Clear() //清空栈
{
    if (base) //如果栈存在
        top = base;
}
Stack::~Stack() //销毁栈
{
    if (base) {
        delete[] base;
        size = 0;
        top = base = nullptr;
    }
}